package com.quickcode.example.threadpool;

import java.util.concurrent.*;

/**
 * Created by zhangbo on 2020/10/22.
 */
public class ThreadPoolSyn {

    public static final ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(50,100,30, TimeUnit.SECONDS,new ArrayBlockingQueue<Runnable>(1000));


    public static final CountDownLatch COUNT_DOWN_LATCH = new CountDownLatch(100);

    public static void main(String[] args) throws InterruptedException {


        for(int i = 0 ; i < 100 ; i ++) {
            String value = String.valueOf(i);
            EXECUTOR_SERVICE.execute(new Runnable() {
                @Override
                public void run() {
                    out(value);
                }
            });
        }

        COUNT_DOWN_LATCH.await();
        System.out.println("count:" + COUNT_DOWN_LATCH.getCount());

    }


    public synchronized static void out(final String value) {
        System.out.println("输出:" + value + ",count:" + COUNT_DOWN_LATCH.getCount());
        COUNT_DOWN_LATCH.countDown();
    }

}
